package ipfms.stripes;

import able.stripes.AbleActionBean;
import ipfms.stripes.config.iPfmsActionBeanContext;
import net.sourceforge.stripes.action.SimpleMessage;
import net.sourceforge.stripes.validation.SimpleError;

public abstract class BaseActionBean extends AbleActionBean {

    //Default paging implementation - use in all pages
    Integer __pg_max_records = 10;
    Integer __pg_start = 0;
    Integer __pg_total_records = 0;    

    @Override
    public iPfmsActionBeanContext getContext() {
        return (iPfmsActionBeanContext) super.getContext();
    }   

    public String getUserId() {
        if(getContext() != null)
            if(getContext().getCurrentUser() != null)
                return getContext().getCurrentUser().getIdPengguna();
        return "HARDCORE";
    }

    public Boolean getLoggedIn() {
        return getContext().isLoggedIn();
    }

    public Integer get__pg_max_records() {
        return __pg_max_records;
    }

    public void set__pg_max_records(Integer __pg_max_records) {
        this.__pg_max_records = __pg_max_records;
    }

    public Integer get__pg_start() {
        return __pg_start;
    }

    public void set__pg_start(Integer __pg_start) {
        this.__pg_start = __pg_start;
    }

    public Integer get__pg_total_records() {
        return __pg_total_records;
    }

    public void set__pg_total_records(Integer __pg_total_records) {
        this.__pg_total_records = __pg_total_records;
    }  
    
      protected void addSimpleError(String msg) {
        getContext().getValidationErrors().addGlobalError(
                new SimpleError(msg));
    }

    protected void addSimpleMessage(String msg) {
        getContext().getMessages().add(new SimpleMessage(msg));
    }
    
}
